/**
 * =============================================================================
 * Initially made by L4D Health Glow (C)2011 Buster "Mr. Zero" Nielsen
 * Improved by Blaize is Dead for Free Arena
 * =============================================================================
 *
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License, version 3.0, as 
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * As a special exception, AlliedModders LLC gives you permission to link the
 * code of this program (as well as its derivative works) to "Half-Life 2,"
 * the "Source Engine," the "SourcePawn JIT," and any Game MODs that run on 
 * software by the Valve Corporation.  You must obey the GNU General Public
 * License in all respects for all other code used.  Additionally, 
 * AlliedModders LLC grants this exception to all derivative works.  
 * AlliedModders LLC defines further exceptions, found in LICENSE.txt 
 * (as of this writing, version JULY-31-2007), or 
 * <http://www.sourcemod.net/license.php>.
 */

/*
 * ==================================================
 *                    Preprocessor
 * ==================================================
 */

#define TEAM_SPECTATORS		1
#define TEAM_SURVIVORS		2
#define TEAM_INFECTED		3
#define MAXCLIENTS              33 //used to create arrays (MaxClients return 32)
#define MAXSURVIVORS            10
#define MAXINFECTED             10
#define MAXSPECTATORS           20

#define REVOLUTION              1
#define PIRATEMELON             2

#define CVAR_FLAGS              FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY


#define FOR_EACH_CLIENT(%1)													\
    for (new %1 = 1; %1 <= MaxClients; %1++)

#define FOR_EACH_CLIENT_COND(%1,%2)											\
    for (new %1 = 1; %1 <= MaxClients; %1++)								\
        if (%2)

#define FOR_EACH_CLIENT_CONNECTED(%1)										\
    FOR_EACH_CLIENT_COND(%1, IsClientConnected(%1))

#define FOR_EACH_CLIENT_IN_GAME(%1)											\
    FOR_EACH_CLIENT_COND(%1, IsClientInGame(%1))

#define FOR_EACH_BOT(%1)													\
    FOR_EACH_CLIENT_COND(%1, (IsClientInGame(%1) && IsFakeClient(%1)))

#define FOR_EACH_HUMAN(%1)													\
    FOR_EACH_CLIENT_COND(%1, (IsClientInGame(%1) && !IsFakeClient(%1)))

#define FOR_EACH_ALIVE_BOT(%1)												\
    FOR_EACH_CLIENT_COND(%1, (IsClientInGame(%1) && IsFakeClient(%1) && GetClientHealth(%1) > 0 && IsPlayerAlive(%1))) 

#define FOR_EACH_ALIVE_HUMAN(%1)											\
    FOR_EACH_CLIENT_COND(%1, (IsClientInGame(%1) && !IsFakeClient(%1) && GetClientHealth(%1) > 0 && IsPlayerAlive(%1)))

#define FOR_EACH_ALIVE_CLIENT(%1)											\
    FOR_EACH_CLIENT_COND(%1, (IsClientInGame(%1) && GetClientHealth(%1) > 0 && IsPlayerAlive(%1)))

#define FOR_EACH_DEAD_BOT(%1)												\
    FOR_EACH_CLIENT_COND(%1, (IsClientInGame(%1) && IsFakeClient(%1) && !IsPlayerAlive(%1))) 

#define FOR_EACH_DEAD_HUMAN(%1)												\
    FOR_EACH_CLIENT_COND(%1, (IsClientInGame(%1) && !IsFakeClient(%1) && !IsPlayerAlive(%1)))

#define FOR_EACH_DEAD_CLIENT(%1)											\
    FOR_EACH_CLIENT_COND(%1, (IsClientInGame(%1) && !IsPlayerAlive(%1)))

#define FOR_EACH_BOT_ON_TEAM(%1,%2)											\
    FOR_EACH_BOT(%1)														\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_HUMAN_ON_TEAM(%1,%2)										\
    FOR_EACH_HUMAN(%1)														\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_ALIVE_BOT_ON_TEAM(%1,%2)									\
    FOR_EACH_ALIVE_BOT(%1)													\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_ALIVE_HUMAN_ON_TEAM(%1,%2)									\
    FOR_EACH_ALIVE_HUMAN(%1)												\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_DEAD_BOT_ON_TEAM(%1,%2)									\
    FOR_EACH_DEAD_BOT(%1)													\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_DEAD_HUMAN_ON_TEAM(%1,%2)									\
    FOR_EACH_DEAD_HUMAN(%1)													\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_CLIENT_ON_TEAM(%1,%2)										\
    FOR_EACH_CLIENT_IN_GAME(%1)												\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_ALIVE_CLIENT_ON_TEAM(%1,%2)								\
    FOR_EACH_ALIVE_CLIENT(%1)												\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_DEAD_CLIENT_ON_TEAM(%1,%2)									\
    FOR_EACH_DEAD_CLIENT(%1)												\
        if (L4DTeam:GetClientTeam(%1) == %2)

#define FOR_EACH_SURVIVOR_BOT(%1)											\
    FOR_EACH_BOT_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_SURVIVOR_HUMAN(%1)											\
    FOR_EACH_HUMAN_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_ALIVE_SURVIVOR_BOT(%1)										\
    FOR_EACH_ALIVE_BOT_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_ALIVE_SURVIVOR_HUMAN(%1)									\
    FOR_EACH_ALIVE_HUMAN_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_DEAD_SURVIVOR_BOT(%1)										\
    FOR_EACH_DEAD_BOT_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_DEAD_SURVIVOR_HUMAN(%1)									\
    FOR_EACH_DEAD_HUMAN_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_SURVIVOR(%1)												\
    FOR_EACH_CLIENT_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_ALIVE_SURVIVOR(%1)											\
    FOR_EACH_ALIVE_CLIENT_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_DEAD_SURVIVOR(%1)											\
    FOR_EACH_DEAD_CLIENT_ON_TEAM(%1, L4DTeam_Survivor)

#define FOR_EACH_SURVIVOR_INCAP(%1)											\
    FOR_EACH_ALIVE_CLIENT_ON_TEAM(%1, L4DTeam_Survivor)						\
        if (L4D_IsPlayerIncapacitated(%1))

#define FOR_EACH_SURVIVOR_INCAP_BOT(%1)										\
    FOR_EACH_ALIVE_BOT_ON_TEAM(%1, L4DTeam_Survivor)						\
        if (L4D_IsPlayerIncapacitated(%1))

#define FOR_EACH_SURVIVOR_INCAP_HUMAN(%1)									\
    FOR_EACH_ALIVE_HUMAN_ON_TEAM(%1, L4DTeam_Survivor)						\
        if (L4D_IsPlayerIncapacitated(%1))

#define FOR_EACH_INFECTED_BOT(%1)											\
    FOR_EACH_BOT_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_INFECTED_HUMAN(%1)											\
    FOR_EACH_HUMAN_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_ALIVE_INFECTED_BOT(%1)										\
    FOR_EACH_ALIVE_BOT_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_ALIVE_INFECTED_HUMAN(%1)									\
    FOR_EACH_ALIVE_HUMAN_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_DEAD_INFECTED_BOT(%1)										\
    FOR_EACH_DEAD_BOT_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_DEAD_INFECTED_HUMAN(%1)									\
    FOR_EACH_DEAD_HUMAN_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_INFECTED(%1)												\
    FOR_EACH_CLIENT_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_ALIVE_INFECTED(%1)											\
    FOR_EACH_ALIVE_CLIENT_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_DEAD_INFECTED(%1)											\
    FOR_EACH_DEAD_CLIENT_ON_TEAM(%1, L4DTeam_Infected)

#define FOR_EACH_HUMAN_SPECTATOR(%1)										\
    FOR_EACH_HUMAN_ON_TEAM(%1, L4DTeam_Spectator)


/* PLAYERS */
#define IsValidClientIndex(%1) \
((%1 > 0) && (%1 <= MaxClients))

#define IsValidClient(%1) \
(IsValidClientIndex(%1) && IsClientInGame(%1) && IsClientConnected(%1))

#define IsValidClientAlive(%1) \
(IsValidClient(%1) && IsClientAlive(%1))

#define IsValidClientDead(%1) \
(IsValidClient(%1) && !IsClientAlive(%1))

#define IsClientAlive(%1) \
(GetClientHealth(%1) > 0 && IsPlayerAlive(%1))

#define IsClientDead(%1) \
(!IsPlayerAlive(%1))

#define IsValidHumanClient(%1) \
(IsValidClient(%1) && !IsFakeClient(%1))

#define IsValidBotClient(%1) \
(IsValidClient(%1) && IsFakeClient(%1))

/* SURVIVORS */
#define IsValidSurvivor(%1) \
(IsValidClient(%1) && GetClientTeam(%1) == TEAM_SURVIVORS)

#define IsValidSurvivorAlive(%1) \
(IsValidSurvivor(%1) && IsClientAlive(%1))

#define IsValidSurvivorDead(%1) \
(IsValidSurvivor(%1) && IsClientDead(%1))

#define IsValidHumanSurvivor(%1) \
(IsValidHumanClient(%1) && GetClientTeam(%1) == TEAM_SURVIVORS)

#define IsValidBotSurvivor(%1) \
(IsValidBotClient(%1) && GetClientTeam(%1) == TEAM_SURVIVORS)

#define IsValidHumanSurvivorAlive(%1) \
(IsValidHumanSurvivor(%1) && IsClientAlive(%1))

#define IsValidBotSurvivorAlive(%1) \
(IsValidBotSurvivor(%1) && IsClientAlive(%1))

#define IsValidBotSurvivorDead(%1) \
(IsValidBotSurvivor(%1) && !IsClientAlive(%1))

/* INFECTED */
#define IsValidInfected(%1) \
(IsValidClient(%1) && GetClientTeam(%1) == TEAM_INFECTED)

#define IsValidInfectedAlive(%1) \
(IsValidInfected(%1) && IsClientAlive(%1))
 
#define IsValidHumanInfected(%1) \
(IsValidHumanClient(%1) && GetClientTeam(%1) == TEAM_INFECTED)

#define IsValidBotInfected(%1) \
(IsValidBotClient(%1) && GetClientTeam(%1) == TEAM_INFECTED)

#define IsValidHumanInfectedAlive(%1) \
(IsValidHumanInfected(%1) && IsClientAlive(%1))

#define IsValidBotInfectedAlive(%1) \
(IsValidBotInfected(%1) && IsClientAlive(%1))

/* SPECTATOR */
#define IsValidSpectator(%1) \
(IsValidClient(%1) && GetClientTeam(%1) == TEAM_SPECTATORS)
